package com.xuetang9.t9.xinhuaxia.mappers;

import com.xuetang9.t9.xinhuaxia.beans.Goods;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface GoodsMapper extends Mapper<Goods> {
    @Select("select * from goods order by goodsId desc")
    @Results( id="goods", value = {
            @Result(property = "firstCategory",column = "goodsFirstCategoryId",
            one =@One(select = "com.xuetang9.t9.xinhuaxia.mappers.FirstCategoryMapper.selectByPrimaryKey")),

            @Result(property = "secondCategory",column = "goodsSecondCategoryId",
            one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.SecondCategoryMapper.selectByPrimaryKey")),

            @Result(property = "goodsPicturepaths",column = "goodsId",
            one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.GoodsPicturepathMapper.queryByGoodsId")),

            @Result(property = "goodsid",column = "goodsId"),
            @Result(property = "goodsname",column = "goodsName"),
            @Result(property = "goodsfirstcategoryid",column = "goodsFirstCategoryId"),
            @Result(property = "goodssecondcategoryid",column = "goodsSecondCategoryId"),
            @Result(property = "goodsbrand",column = "goodsBrand"),
            @Result(property = "goodsdiscount",column = "goodsDiscount"),
            @Result(property = "goodsprice",column = "goodsPrice"),
            @Result(property = "goodsstatus",column = "goodsStatus"),
            @Result(property = "goodslabel",column = "goodsLabel"),
    })
    List<Goods> queryAll();

    @Select("select * from goods where goodsId = #{id}")
    @ResultMap("goods")
    Goods queryById(@Param("id") Long id);




    @Select("select * from goods where goodsLabel = #{lable} and goodsStatus = 1 order by goodsId desc")
    @ResultMap("goods")
    List<Goods>queryByLable(@Param("lable")String lable);



    @Select("select * from goods where goodsFirstCategoryId=#{fid}")
    @Results({
            @Result(property = "firstCategory", column = "goodsFirstCategoryId",
                    one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.FirstCategoryMapper.selectByPrimaryKey")),
            @Result(property = "secondCategory", column = "goodsSecondCategoryId",
                    one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.SecondCategoryMapper.selectByPrimaryKey")),
            @Result(property = "goodsPicturepaths", column = "goodsId",
                    one = @One(select = "com.xuetang9.t9.xinhuaxia.mappers.GoodsPicturepathMapper.queryByGoodsId")),
            @Result(property = "goodsid", column = "goodsId"),
            @Result(property = "goodsname", column = "goodsName"),
            @Result(property = "goodsfirstcategoryid", column = "goodsFirstCategoryId"),
            @Result(property = "goodssecondcategoryid", column = "goodsSecondCategoryId"),
            @Result(property = "goodsbrand", column = "goodsBrand"),
            @Result(property = "goodsdiscount", column = "goodsDiscount"),
            @Result(property = "goodsprice", column = "goodsPrice"),
            @Result(property = "goodsstatus", column = "goodsStatus"),
            @Result(property = "goodslabel", column = "goodsLabel"),
    })
    List<Goods> queryAllByFirstCatgory(@Param("fid") Long fid);
}